import pymysql

#
# # 建立mysql连接；
# conn = pymysql.connect(host='127.0.0.1',  # ip地址
#                        port=3306,  # 端口
#                        user='root',  # 登录用户
#                        password='123456',  # 登陆密码
#                        db='my_test',  # 连接的数据库
#                        charset='utf8',  # 编码格式，可不加，建议加上
#                        # cursorclass=pymysql.cursors.DictCursor  # 将sql结果以字典方式返回，可省略
#                        )

# 建立mysql连接；
mysql_config = {"host":'127.0.0.1', "port":3306, "user":'root', "password":'123456',"db":'my_test',"charset":'utf8'}
conn = pymysql.connect(**mysql_config, cursorclass=pymysql.cursors.DictCursor)
# 获取游标，目的就是要执行sql语句
cursor = conn.cursor()

# 执行的是查询sql
sql = "select * from student;"
cursor.execute(sql)
values = cursor.fetchall()
print(values)

# # 执行更新sql
# # sql = """insert into student values(14, "张三", 28, "男", 15555555555);"""
# sql = """delete from student where name = '张三';"""
# cursor.execute(sql)
# # 执行更新sql的时候，需要commit
# conn.commit()

cursor.close()
conn.close()